package com.toe.admin.controller;

import com.toe.business.service.BusinessInformationTempService;
import com.toe.common.restful.JsonPage;
import com.toe.common.restful.JsonResult;
import com.toe.pojo.dto.business.BusinessInformationTempDTO;
import com.toe.pojo.vo.business.BusinessInformationTempVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin")
@Api(tags = "商家入驻管理")
public class ApplicationController {
    @DubboReference
    BusinessInformationTempService dubboBusinessInfoTempService;

    @PostMapping("/apply")
    @ApiOperation("入驻申请")
    public JsonResult<Void> applyForResidence(@RequestBody BusinessInformationTempDTO businessInformationTempDTO) {
        dubboBusinessInfoTempService.addApplication(businessInformationTempDTO);
        return JsonResult.ok();
    }

    @ApiOperation(value = "分页查询申请列表")
    @GetMapping("/page/{pageNum}/{pageSize}")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "页码", name = "pageNum",example = "1"),
            @ApiImplicitParam(value = "每页条数", name = "pageSize", example = "5")
    })
    public JsonResult<JsonPage<BusinessInformationTempVO>> examineForResidence(@PathVariable Integer pageNum, @PathVariable Integer pageSize) {
        JsonPage<BusinessInformationTempVO> jsonPage = dubboBusinessInfoTempService.QueryApplication(pageNum, pageSize);
        return JsonResult.ok(jsonPage);
    }

    @PostMapping("/forbid/{id}")
    @ApiOperation("审核不通过")
    public JsonResult<Void> applyForbidForResidence(@PathVariable Long id) {
        dubboBusinessInfoTempService.forbidApplication(id);
        return JsonResult.ok();
    }

    @PostMapping("/pass/{id}")
    @ApiOperation("审核通过商家入驻")
    public JsonResult<Void> applyPassForResidence(@PathVariable Long id) {
        dubboBusinessInfoTempService.passApplication(id);
        return JsonResult.ok();
    }

}
